import java.time.DayOfWeek;
import java.time.LocalDate;

public class CalendarTest {
    public static void main(String[] args) {
        LocalDate date = LocalDate.now();
        int month = date.getMonthValue();
        int today = date.getDayOfMonth();

        date = date.minusDays(today - 1);   // 回到月初
        DayOfWeek weekday = date.getDayOfWeek();
        int value = weekday.getValue();     // 1 = Monday, ..., 7 = Sunday

        System.out.println("Mon Tue Wed Thu Fri Sat Sun");

        // 上个月的最后几天不显示出来
        for (int i = 1; i < value; i++) {
            System.out.print("    ");
        }

        // 进入到下个月终止循环
        while (date.getMonthValue() == month) {

            // 打印这一天
            System.out.printf("%3d", date.getDayOfMonth());

            // 这一天是今天，标星
            if (date.getDayOfMonth() == today) {
                System.out.print("*");
            } else {
                System.out.print(" ");
            }

            date = date.plusDays(1); // 下一天

            // 下一天是周一，换行
            if (date.getDayOfWeek().getValue() == 1) {
                System.out.println();
            }
        }

        // 循环的最后一次没有换行，这里需要换行
        if (date.getDayOfWeek().getValue() != 1) {
            System.out.println();
        }
    }
}
